package com.visualexpress.data;

import java.util.ArrayList;

public class Order implements Details{
	
	private String orderNumber;
	private String startCity;
	private String endCity;
	private Time startTime;
	private Time endTime;
	private ArrayList<String> passByCities;
	private ArrayList<Time> arriveTimes;
	private ArrayList<Time> leaveTimes;
	private ArrayList<Integer> ways;
	private boolean deliverid;

	private static int count = 0;
	public static final int START   = -1;
	public static final int HIGHWAY = 0;
	public static final int RIALWAY = 1;
	public static final int AIRLINE = 2;

	
	public static void main(String[] args){
		
		Time temp = new Time(2005,6,23,12);
		System.out.println(temp);
		temp.addTime(13);
		System.out.println(temp);
		
	}//end of main()
	
	public Order(){
		
		String orderNumber = Order.makeOrderNum();
		this.setOrderNumber(orderNumber);
		this.setDeliverid(false);
		
		this.passByCities = new ArrayList<String>();
		this.arriveTimes  = new ArrayList<Time>();
		this.leaveTimes   = new ArrayList<Time>();
		this.ways         = new ArrayList<Integer>();
	}
	
	public Order(String startCity, Time startTime, String endCity){
		
		this();
		this.setStartCity(startCity);
		this.setStartTime(startTime);
		this.setEndCity(endCity);
	}
	
	public String getOrderNumber() {
		return orderNumber;
	}

	public ArrayList<String> getPassByCities() {
		return passByCities;
	}

	public ArrayList<Time> getArriveTimes() {
		return arriveTimes;
	}

	public ArrayList<Time> getLeaveTimes() {
		return leaveTimes;
	}

	public ArrayList<Integer> getWays() {
		return ways;
	}

	private void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}

	private static String makeOrderNum(){

		Order.count++;
		String istr = new Integer(Order.count).toString();
		String zero = "";
		for (int j = 0; j < 9 - istr.length(); j++) {
			zero += "0";
		}
		String orderNum = "EV" + zero + istr + "CN";
		
		return orderNum;
	}

	public String getStartCity() {
		return startCity;
	}

	private void setStartCity(String startCity) {
		this.startCity = startCity;
	}

	public String getEndCity() {
		return endCity;
	}

	private void setEndCity(String endCity) {
		this.endCity = endCity;
	}

	public Time getStartTime() {
		return startTime;
	}

	private void setStartTime(Time startTime) {
		this.startTime = startTime;
	}

	public Time getEndTime() {
		return endTime;
	}

	public void setEndTime(Time endTime) {
		this.endTime = endTime;
		this.setDeliverid(true);
	}

	public boolean isDeliverid() {
		return deliverid;
	}

	private void setDeliverid(boolean state) {
		this.deliverid = state;
	}

	public void addPassByCity(String c, Time ad, Time ld, int w){

		this.passByCities.add(c);
		this.arriveTimes.add(ad);
		this.leaveTimes.add(ld);
		this.ways.add(w);
	}//end of addCityPassedBy()

	public void showDetail() {
		System.out.println("This is an EMS order :");
		System.out.print("  OrderNumber :" + orderNumber);
		System.out.print("  From " + startCity + " to " + endCity);
		System.out.println(" (began at " + startTime + ")");
		
		for(int i = 0; i < this.passByCities.size(); i++){
			System.out.print("  "+this.passByCities.get(i) + " arrives by");
			int way = this.ways.get(i).intValue();
			switch(way){
			case Order.START:
				System.out.print(" customer");
				break;
			case Order.HIGHWAY:
				System.out.print("  highway");
				break;
			case Order.RIALWAY:
				System.out.print("  rainway");
				break;
			case Order.AIRLINE:
				System.out.print("  airline");
				break;
			}
			System.out.print(" @ "+this.arriveTimes.get(i));
			System.out.println(" leaves @ "+this.leaveTimes.get(i));
		}
		
		if(deliverid == true){
			System.out.println("  The mail has been deliveried at " + endTime);
		}
		else{
			System.out.println("  The mail has not been delivered yet!");
		}
		System.out.println();
	}//end of showDetail()

}//end of class
